var app = getApp();
Page({
    data: {
        //判断小程序的API，回调，参数，组件等是否在当前版本可用。
        canIUse: wx.canIUse('button.open-type.getUserInfo'),
        isWxapp: true,
        userInfo: {
            id: 0,
            avatar: '/assets/images/avatar.png',
            nickname: '游客',
            balance: 0,
            score: 0,
            level: 0
        }
    },
    onLoad: function () {
        if (app.globalData.userInfo) {
            wx.switchTab({
                url: '../index/index'
            })
        }
    },

    isWxapp: function () {
        return app.globalData.userInfo ? app.globalData.userInfo.username.match(/^u\d+$/) : true;
    },
    login: function () {
        var that = this;
        app.login(function () {
            that.setData({ userInfo: app.globalData.userInfo, isWxapp: that.isWxapp() });
        });
        wx.switchTab({
            url: '../index/index'
        })
    }
})